/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.baratongoweb.model;


import com.baratongoweb.model.Model;
import com.baratongoweb.modelos.Factura;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

/**
 *
 * @author vane
 */
public class FacturaDAO extends Model implements IDAO<Factura>{
    private PreparedStatement ps,ps2;
    private PreparedStatement psInsert;
    private PreparedStatement psEliminar;
    private PreparedStatement psModificar;

    public Factura consultar(String codigo) throws SQLException {


        Factura f=new Factura();
        String sql="select codigo, fecha, total, subtotal, iva, codigo_ingresos"
                + "from facturas where codigo="+codigo;
        if(ps==null){
            ps=getCon().prepareStatement(sql);
        }
        ResultSet rs=ps.executeQuery();
        f.setCodigo(rs.getString("codigo"));
        f.setFecha(rs.getDate("fecha"));
        f.setIva(rs.getDouble("iva"));
        f.setSubtotal(rs.getDouble("subtotal"));
        f.setTotal(rs.getDouble("total"));
        return f;
    }

    public void insertar(Factura t) throws SQLException {

        String sql="insert into facturas(codigo, fecha, iva, subtotal, total) "
                + "values(?,?,?,?,?)";
        if(psInsert==null){
            psInsert=getCon().prepareStatement(sql);
        }
        psInsert.setString(1, t.getCodigo());
        psInsert.setDate(2, (Date) t.getFecha());
        psInsert.setDouble(3, t.getIva());
        psInsert.setDouble(4, t.getSubtotal());
        psInsert.setDouble(5, t.getTotal());
        psInsert.executeUpdate();
    }

    public void modificar(Factura t) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void eliminar(Factura t) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public LinkedList<Factura> listar() throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
